package org.tinygroup.serviceweblayer.test.testcase;

import junit.framework.TestCase;

import org.tinygroup.beancontainer.BeanContainerFactory;
import org.tinygroup.serviceweblayer.processor.JsonServiceTinyProcessor;
import org.tinygroup.tinyrunner.Runner;

public class JsonTestCase extends TestCase {

	public void testJson() {
		Runner.init(null, null);
		JsonServiceTinyProcessor processor = BeanContainerFactory
				.getBeanContainer(JsonTestCase.class.getClassLoader()).getBean(
						JsonServiceTinyProcessor.BEAN_NAME);
		
		process(processor,"{\"head\":{\"serviceid\":\"basicServiceInt\"},\"body\":{\"i\":1}}");
		process(processor,"{\"head\":{\"serviceid\":\"basicServiceIntArray\"},\"body\":{\"i\":[1,2,3,4],\"a\":\"a\"}}");
		process(processor,"{\"head\":{\"serviceid\":\"basicServiceBoolean\"},\"body\":{\"i\":true,\"a\":\"a\"}}");
		process(processor,"{\"head\":{\"serviceid\":\"basicServiceBooleanArray\"},\"body\":{\"i\":[true,false,true,false],\"a\":\"a\"}}");
		process(processor,"{\"head\":{\"serviceid\":\"basicServiceInteger\"},\"body\":{\"i\":1,\"a\":\"a\"}}");
		process(processor,"{\"head\":{\"serviceid\":\"basicServiceIntegerArray\"},\"body\":{\"i\":[1,2,3,4],\"a\":\"a\"}}");
		process(processor,"{\"head\":{\"serviceid\":\"basicServiceIntegerList\"},\"body\":{\"i\":[1,2,3,4],\"a\":\"a\"}}");
		process(processor,"{\"head\":{\"serviceid\":\"basicWrapperServiceBoolean\"},\"body\":{\"i\":true,\"a\":\"a\"}}");
		process(processor,"{\"head\":{\"serviceid\":\"basicWrapperServiceBooleanList\"},\"body\":{\"i\":[true,false,true,false],\"a\":\"a\"}}");
		process(processor,"{\"head\":{\"serviceid\":\"objectServiceGrade\"},\"body\":{\"grade\":{\"name\":\"a\",\"age\":1},\"a\":\"a\"}}");
		process(processor,"{\"head\":{\"serviceid\":\"objectServiceGradeList\"},\"body\":{\"grade\":[{\"name\":\"a\",\"age\":1},{\"name\":\"b\",\"age\":2},{\"name\":\"c\",\"age\":3}],\"a\":\"a\"}}");
		process(processor,"{\"head\":{\"serviceid\":\"objectServiceGradeArray\"},\"body\":{\"grade\":[{\"name\":\"a\",\"age\":1},{\"name\":\"b\",\"age\":2},{\"name\":\"c\",\"age\":3}],\"a\":\"a\"}}");
	
	}

	private void process(JsonServiceTinyProcessor processor, String json) {
		System.out.println("request:");
		System.out.println("		"+json);
		String result = processor.process(json);
		System.out.println("result:");
		System.out.println("		"+result);
	}
}
